<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 错误的集合 -->
    <script>
      var findErrorNums = function (nums) {
        nums.sort((a, b) => a - b)
        let a = []
        for (let i = 0; i < nums.length; i++) {
          //找重复
          if (nums[i] == nums[i + 1]) {
            a.push(nums[i])
          }
        }
        for (let j = 1; j < nums.length + 1; j++) {
          //找缺失
          if (nums.indexOf(j) == -1) {
            a.push(j)
          }
        }
        return a
      }
      console.log(findErrorNums([1, 2, 2, 4]))
    </script>
  </body>
</html>
